In [106]:
import pandas as pd
import numpy as np
from numpy import log, abs, sign, sqrt
import ibmcognitive

data = pd.read_csv("http://recenter.tamu.edu/data/hs/text/trends_hs.csv", index_col=0).T

In [107]:
def months(date) : return date[0:4] + "-" + date[5:7] + "-01"

D = (data / np.mean(data))
D['Label'] = D.index
D['date'] = D.apply(lambda row: months(row['Label']), axis=1)
D['month'] = D.apply(lambda row: int(row['Label'][5:7]), axis=1)
P = D.groupby('month').mean().stack().to_frame()
P = P.reset_index(level=0).reset_index(level=0)
P.columns=['Name', 'Month', 'Housing']

In [108]:
%%brunel line x(month) y(housing) color(Name) legends(none) 
    style(".element {stroke-width:0.5px}")
    :: width=900


Out[108]:

from sklearn.cluster import KMeans cl = KMeans(3) P.pivot('Month')


In [121]:
D


Out[121]:
Area_Name Abilene Amarillo Arlington Austin Bay Area Beaumont Brazoria County Brownsville Bryan-College Station Collin County ... Temple-Belton Texarkana Texas Tyler Victoria Waco Wichita Falls Label date month
2015_05 1.368468 1.410058 1.510708 1.467943 1.450880 1.578372 1.390545 1.210341 1.872973 1.475127 ... 1.271143 1.387506 1.410010 1.420898 1.212486 1.457100 1.469401 2015_05 2015-05-01 5
2015_04 1.267568 1.306072 1.160831 1.320958 1.267570 1.422208 1.413155 1.305895 1.379321 1.246025 ... 1.171724 1.215720 1.262874 1.353944 1.112634 1.308078 1.089384 2015_04 2015-04-01 4
2015_03 1.248649 1.318550 1.133709 1.271643 1.271470 1.533753 1.254882 1.067011 1.553551 1.134643 ... 1.278244 1.215720 1.221861 1.543645 1.027047 1.330156 1.283615 2015_03 2015-03-01 3
2015_02 0.945946 0.781979 0.791969 0.943199 0.992605 1.171230 0.915725 0.875905 0.977624 0.845776 ... 0.774048 1.123219 0.898675 0.866673 0.841608 1.026593 0.844483 2015_02 2015-02-01 2
2015_01 0.983784 0.848531 0.707890 0.790947 0.781993 0.842170 0.780062 0.652947 0.837272 0.698172 ... 0.759845 0.991076 0.781610 0.922468 0.770285 0.794782 0.599583 2015_01 2015-01-01 1
2014_12 1.002703 0.994112 1.114723 1.187378 1.187616 1.126612 1.243577 0.859979 0.967945 1.117438 ... 1.058102 1.110005 1.171712 1.234916 0.984253 1.164576 0.920487 2014_12 2014-12-01 12
2014_11 0.996396 0.940039 0.924868 0.981502 1.068659 1.003911 1.085303 0.875905 0.817913 0.935424 ... 0.802453 0.951433 0.966746 1.115888 0.884402 0.894129 0.810704 2014_11 2014-11-01 11
2014_10 1.198198 1.110577 1.291018 1.238607 1.355325 1.450094 1.695786 1.274043 1.055060 1.193504 ... 1.150420 1.242149 1.233859 1.372542 1.112634 1.208731 0.945821 2014_10 2014-10-01 10
2014_09 1.267568 1.131374 1.255759 1.275473 1.302672 1.249312 1.187050 1.146639 0.987304 1.250553 ... 0.951582 1.176077 1.232253 1.342785 1.326602 1.291520 0.928932 2014_09 2014-09-01 9
2014_08 1.280180 1.160490 1.421205 1.447356 1.632240 1.461249 1.390545 1.305895 1.442238 1.527648 ... 1.278244 1.162863 1.395201 1.290711 1.298073 1.269443 1.156942 2014_08 2014-08-01 8
2014_07 1.456757 1.268637 1.404931 1.508640 1.534735 1.182384 1.232271 1.401448 1.950409 1.615486 ... 1.313751 1.321435 1.453382 1.379982 1.355132 1.335675 1.266725 2014_07 2014-07-01 7
2014_06 1.450450 1.459972 1.456464 1.529706 1.565936 1.416630 1.582734 1.114788 1.824576 1.616391 ... 1.292447 1.268577 1.473261 1.573402 1.255280 1.440542 1.038715 2014_06 2014-06-01 6
2014_05 1.204505 1.206245 1.372385 1.521567 1.468431 1.372012 1.345324 1.289969 1.708422 1.435283 ... 1.363460 1.149648 1.387018 1.443215 1.312338 1.319117 1.182277 2014_05 2014-05-01 5
2014_04 1.122523 1.081461 1.234061 1.288400 1.349474 1.160075 1.051387 1.114788 1.466436 1.189881 ... 1.136217 1.215720 1.234160 1.201440 1.141163 1.208731 1.207611 2014_04 2014-04-01 4
2014_03 1.040541 1.014909 1.158119 1.165354 1.140813 1.015066 1.073998 1.082937 1.330924 1.086650 ... 0.930278 1.176077 1.123520 1.048935 1.169692 1.103864 0.861373 2014_03 2014-03-01 3
2014_02 0.863964 0.852690 0.911307 0.911121 0.973104 1.037375 0.938335 0.923681 0.827593 0.881997 ... 0.589413 0.832504 0.897973 0.907589 0.813079 0.723031 0.785370 2014_02 2014-02-01 2
2014_01 0.725225 0.682152 0.694329 0.757432 0.758592 0.825438 0.621788 0.796277 0.735638 0.710850 ... 0.802453 0.964647 0.764943 0.885271 0.841608 0.800301 0.751590 2014_01 2014-01-01 1
2013_12 0.914414 1.019069 1.071328 1.060022 1.105711 1.182384 0.768756 1.098862 0.919547 1.019640 ... 0.845061 0.951433 1.042899 0.888991 1.027047 0.855494 0.776925 2013_12 2013-12-01 12
2013_11 0.914414 0.869328 0.889609 0.979108 0.899000 0.987179 0.938335 0.605171 0.803394 0.965307 ... 0.923176 0.938219 0.945763 0.941066 1.340867 0.987958 0.793814 2013_11 2013-11-01 11
2013_10 1.053153 1.064823 1.190666 1.125136 1.148613 1.048530 0.813977 0.987384 0.793715 1.056767 ... 1.065203 1.096791 1.096764 1.011739 0.955724 0.855494 0.962711 2013_10 2013-10-01 10
2013_09 1.229730 1.068982 1.193378 1.218020 1.156414 1.187962 1.220966 0.907756 0.900189 1.239686 ... 1.015494 1.308220 1.155246 1.067533 1.326602 1.120421 1.080939 2013_09 2013-09-01 9
2013_08 1.488288 1.193766 1.356111 1.588596 1.437229 1.522599 1.401850 1.178490 1.587429 1.545759 ... 1.370562 1.043933 1.422861 1.327907 1.497777 1.341194 1.258280 2013_08 2013-08-01 8
2013_07 1.374775 1.281115 1.356111 1.616366 1.507433 1.148921 1.232271 1.067011 1.945569 1.610958 ... 1.122014 1.043933 1.455892 1.372542 1.069841 1.286001 1.266725 2013_07 2013-07-01 7
2013_06 1.318018 1.143853 1.228637 1.421980 1.376776 1.293930 1.413155 1.401448 1.727781 1.561153 ... 1.292447 1.043933 1.361165 1.246075 1.241015 1.252885 1.021825 2013_06 2013-06-01 6
2013_05 1.418919 1.264477 1.502571 1.523482 1.495733 1.372012 1.390545 1.178490 1.650346 1.536704 ... 1.327954 1.123219 1.432248 1.212598 1.255280 1.308078 1.216056 2013_05 2013-05-01 5
2013_04 1.343243 1.256158 1.158119 1.288879 1.177865 1.104302 1.390545 1.098862 1.292206 1.393628 ... 0.987088 0.977862 1.240736 1.074972 1.098370 1.054190 1.047159 2013_04 2013-04-01 4
2013_03 1.034234 1.048185 1.093026 1.141415 1.051108 0.948138 1.062693 1.067011 0.905028 1.215237 ... 0.972886 0.740003 1.129745 1.108449 0.955724 1.004516 1.342729 2013_03 2013-03-01 3
2013_02 0.882883 0.727906 0.897746 0.859412 0.875598 0.780820 0.904419 0.796277 0.604965 0.785104 ... 0.901872 0.541788 0.846468 0.844355 0.870137 0.899649 0.852928 2013_02 2013-02-01 2
2013_01 0.718919 0.777820 0.800106 0.749771 0.729340 0.886788 0.746146 0.939607 0.682401 0.700889 ... 0.610717 0.541788 0.748377 0.732767 0.684698 0.651279 0.667142 2013_01 2013-01-01 1
2012_12 0.983784 0.948358 0.889609 0.964266 0.889249 0.892366 0.915725 1.003309 0.648523 0.919125 ... 0.887669 0.951433 0.937881 0.870393 0.927195 0.899649 0.971156 2012_12 2012-12-01 12
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2011_06 1.343243 1.148012 1.049630 1.115082 0.943852 0.987179 0.915725 1.210341 1.374481 1.152754 ... 1.413170 1.162863 1.094906 1.164243 1.141163 1.037632 0.937377 2011_06 2011-06-01 6
2011_05 1.141441 0.994112 0.886897 0.989162 0.930201 0.797552 1.164440 0.796277 1.151854 0.920936 ... 1.136217 0.700360 0.984015 1.008019 1.212486 1.114902 1.080939 2011_05 2011-05-01 5
2011_04 0.933333 0.940039 0.905882 0.880958 0.908750 0.925829 0.983556 1.051086 0.900189 0.925463 ... 0.937379 0.964647 0.911225 0.941066 0.927195 1.015554 0.937377 2011_04 2011-04-01 4
2011_03 0.826126 0.919242 0.903170 0.842176 0.844397 0.814284 0.847893 1.067011 0.784035 0.836720 ... 0.816656 1.136434 0.880855 0.896430 0.927195 0.883091 1.004935 2011_03 2011-03-01 3
2011_02 0.536036 0.636398 0.469215 0.579325 0.645486 0.602347 0.610483 0.748501 0.488812 0.585885 ... 0.596514 0.673932 0.611182 0.673252 0.599111 0.590567 0.667142 2011_02 2011-02-01 2
2011_01 0.428829 0.507455 0.523459 0.501284 0.563581 0.602347 0.689620 0.764426 0.454934 0.507103 ... 0.546804 0.687146 0.547127 0.531907 0.684698 0.634722 0.675587 2011_01 2011-01-01 1
2010_12 0.731532 0.769501 0.772983 0.747378 0.772243 0.825438 0.859198 0.923681 0.629164 0.747072 ... 0.788250 0.938219 0.793557 0.777402 0.770285 0.827898 0.988046 2010_12 2010-12-01 12
2010_11 0.725225 0.561528 0.705178 0.635343 0.622084 0.836593 0.610483 0.780352 0.488812 0.653801 ... 0.788250 0.726789 0.696220 0.576542 0.813079 0.805820 0.819149 2010_11 2010-11-01 11
2010_10 0.700000 0.898444 0.759422 0.639652 0.735191 0.836593 0.870504 0.700724 0.483972 0.675534 ... 0.745642 0.792861 0.724633 0.751365 0.841608 0.833417 0.954266 2010_10 2010-10-01 10
2010_09 0.731532 0.852690 0.805530 0.673166 0.750791 0.691583 0.870504 1.162565 0.590446 0.690928 ... 0.802453 1.123219 0.775586 0.818318 1.012783 0.750627 1.114718 2010_09 2010-09-01 9
2010_08 0.908108 1.027388 0.843501 0.801959 0.783943 0.970448 0.859198 0.939607 0.948586 0.832193 ... 1.029697 1.110005 0.861226 0.885271 0.741756 0.805820 1.097828 2010_08 2010-08-01 8
2010_07 1.002703 0.757022 0.756710 0.785201 0.811245 0.914675 1.119219 0.844054 0.914708 0.832193 ... 1.001291 0.964647 0.837432 0.948505 0.927195 0.921726 0.878263 2010_07 2010-07-01 7
2010_06 1.065766 1.131374 0.995386 1.048531 1.014056 1.054107 0.927030 0.796277 1.384161 1.050428 ... 1.221433 1.017505 1.103139 0.974542 0.855873 1.015554 1.089384 2010_06 2010-06-01 6
2010_05 1.261261 1.385102 1.220500 1.094494 1.099861 1.126612 1.130524 1.337746 1.364802 1.093894 ... 1.377663 1.162863 1.148720 1.048935 1.369396 1.225289 1.393398 2010_05 2010-05-01 5
2010_04 1.015315 1.218723 1.223212 1.067682 0.990655 1.115457 1.051387 1.178490 1.127656 1.135549 ... 1.356359 1.123219 1.104545 1.175402 1.041312 1.230808 1.410287 2010_04 2010-04-01 4
2010_03 0.838739 0.844371 1.117436 0.951338 0.938002 1.015066 1.040082 1.481075 0.851791 0.938141 ... 1.036798 1.493221 0.987830 0.929907 0.912931 1.059709 1.241391 2010_03 2010-03-01 3
2010_02 0.586486 0.740385 0.745861 0.597998 0.616234 0.602347 0.734841 0.955533 0.517850 0.603091 ... 0.667527 0.819290 0.666552 0.673252 0.870137 0.662318 0.768480 2010_02 2010-02-01 2
2010_01 0.460360 0.445063 0.585840 0.471600 0.448525 0.462915 0.350462 0.907756 0.430735 0.439188 ... 0.603615 0.647503 0.523081 0.595140 0.627640 0.673357 0.751590 2010_01 2010-01-01 1
2009_12 0.781982 0.848531 0.889609 0.721523 0.774193 0.825438 0.859198 0.812203 0.643683 0.727150 ... 0.923176 0.832504 0.817151 0.769963 0.698963 0.894129 0.709366 2009_12 2009-12-01 12
2009_11 0.819820 1.093939 0.976400 0.827813 0.844397 0.764088 0.881809 0.987384 0.716279 0.815893 ... 1.058102 0.806075 0.903444 0.829477 0.741756 0.861014 1.097828 2009_11 2009-11-01 11
2009_10 0.952252 1.106417 1.149982 0.935060 0.889249 0.920252 1.073998 1.098862 0.696920 0.959874 ... 1.043899 0.911790 0.978543 1.015458 0.955724 0.987958 0.996490 2009_10 2009-10-01 10
2009_09 0.807207 1.044025 0.989961 0.925963 0.957503 0.814284 0.881809 0.684798 0.619485 0.949913 ... 1.107811 0.951433 0.935371 1.011739 0.884402 1.004516 0.895152 2009_09 2009-09-01 9
2009_08 0.939640 1.023228 1.109299 0.937933 1.006256 1.042952 0.802672 0.732575 1.205091 1.032317 ... 1.271143 1.123219 0.995963 1.041496 0.912931 1.219769 1.156942 2009_08 2009-08-01 8
2009_07 0.996396 1.056504 1.215076 1.083482 1.086210 1.154498 0.859198 1.274043 1.471276 1.156376 ... 1.249839 0.925004 1.125779 1.208879 1.055576 1.175615 1.359618 2009_07 2009-07-01 7
2009_06 1.179279 1.276955 1.130997 1.079173 1.136913 1.065261 1.006166 0.923681 1.451917 1.134643 ... 1.356359 1.242149 1.094906 1.112168 0.969989 1.203211 1.351174 2009_06 2009-06-01 6
2009_05 0.901802 1.027388 0.951990 0.886703 0.842446 1.015066 1.266187 0.987384 1.287366 0.915502 ... 1.377663 1.110005 0.955401 0.803439 0.855873 1.015554 1.283615 2009_05 2009-05-01 5
2009_04 0.990090 0.944198 0.965551 0.810098 0.838546 0.976025 0.746146 1.688108 0.885669 0.827665 ... 1.022595 0.753218 0.856508 0.822038 0.813079 0.899649 1.190722 2009_04 2009-04-01 4
2009_03 0.826126 0.840212 0.933005 0.717214 0.850247 1.020643 0.791367 0.987384 0.730798 0.832193 ... 0.738541 0.845718 0.837833 0.859234 0.827343 0.932765 1.072494 2009_03 2009-03-01 3
2009_02 0.668468 0.744544 0.686192 0.570707 0.711789 0.775243 0.553957 0.875905 0.440415 0.648368 ... 0.745642 0.700360 0.669715 0.662094 0.656169 0.745108 1.047159 2009_02 2009-02-01 2
2009_01 0.441441 0.628079 0.580416 0.437606 0.565531 0.719470 0.429599 0.764426 0.421056 0.505292 ... 0.575210 0.515360 0.538693 0.554224 0.484994 0.540893 0.743145 2009_01 2009-01-01 1

77 rows × 51 columns